package git.bankview.wl.report;

import java.util.*;
import java.text.*;
import java.sql.*;

import laya.semi.process.*;

import git.bankview.sl.db.*;
import git.bankview.wl.common.*;
import git.bankview.wl.bean.LogonBean;
import git.bankview.sl.report.ReportCommon;
import git.bankview.sl.report.SchdUtil;

import org.apache.log4j.Logger;

public class ReportSchdMonitorActivity extends SqlQueryActivityBase
{
	private static Logger log = Logger.getLogger(ReportSchdMonitorActivity.class);
   
	protected StringBuffer buildSqlBuffer(IProcessContext oCtx)
		throws Exception
	{
		Object[] vStatus = (Object[])oCtx.getField("status");
		
		StringBuffer oSql = new StringBuffer("SELECT");
		oSql.append("  se.schdid  ")	//c01
			.append(", it.transid ")	//c02
			.append(", se.schddate ")	//c03
			.append(", se.schdtype ")	//c04
			.append(", se.schdexport ")	//c05
			.append(", se.schdstatus ")	//c06
			.append(", se.exectime ")	//c07
			.append(", se.termtime ")	//c08
			.append(", se.execmsg ")	//c09
			.append(", se.execdetail ")	//c10
			.append(", gd.paramvalue grpdeptno")	//c11
			.append(", gs.paramvalue grpschddate")	//c12
			.append(", gu.paramvalue grpuserid")	//c13
			.append(", gc.paramvalue grpschduser")	//c14
			.append(", it.translabel")	//c15
			.append(", it.pageurl")		//c16
			.append(" FROM dqSchdEntry se, infotrans it")
			.append(", outer dqschdparam gd, outer dqschdparam gs, outer dqschdparam gu, outer dqschdparam gc")
			.append(" WHERE gd.paramname = 'GRP_DEPT_NO' and gd.schdid = se.schdid")
			.append(" and gs.paramname = 'GRP_SCHD_DATE' and gs.schdid = se.schdid")
			.append(" and gu.paramname = 'GRP_USER_ID' and gu.schdid = se.schdid")
			.append(" and gc.paramname = 'GRP_SCHD_USER' and gc.schdid = se.schdid")
			.append(" and it.statuscode = 0 and it.transfunc = 'REPORT' and se.transid = it.transid");
		
		if (null != vStatus && 0 < vStatus.length)
		{
			oSql.append(" and (");
			for (int i = 0; i < vStatus.length; ++i)
			{
				Integer status = (Integer)vStatus[i];
				
				if (0 < i)
					oSql.append(" or ");
				
				if (0 > status.intValue())
					oSql.append("se.schdstatus < 0");
				else
					oSql.append("se.schdstatus = ").append(status);
			}
			oSql.append(")");
		}
		
		return oSql;
	}
}
